package com.jf3q.common.utils;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public  class OrderCodeUtils {

    /**
     * 生成编号(当前日期后六位+4位随机数组成)
     *
     * @return
     * @throws Exception
     */
    public static String createOrderCode(Date date) {

        //生成格式化日期为"yymmdd"
        DateFormat format = new SimpleDateFormat("yyMMdd");
        if (null == date) {
            date = new Date();
        }
        StringBuffer buffer = new StringBuffer();
        buffer.append(format.format(date));
        String code = buffer.toString();

        //随机生成四位数
        String timeMillis = System.currentTimeMillis() + "";
        String randomNum = timeMillis.substring(timeMillis.length() - 4);

        //生成订单编号
        String orderCode = code + randomNum;

        return orderCode;
    }
}

